package Server.Poker.BJZ;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Map;

import org.json.JSONObject;

import Server.Model.Base.SHMUser;


class IJsonExport {
	public String toString() {
		return getJsonData();
	}

	private String getJsonData() {
		return "";
	}

	public static String sprintf_BYTE(int by[][], int count) {

		int tmpCardData[] = new int[count]; // �û��˿�
		for (int i = 0; i < by.length; i++) {
			for (int k = 0; k < by[i].length; k++) {
				tmpCardData[i * by[i].length + k] = by[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, count);
		return strCardData;
	}

	public static String sprintf_BYTE(Integer by[][], int count) {

		int tmpCardData[] = new int[count]; // 用户扑克
		for (int i = 0; i < by.length; i++) {
			for (int k = 0; k < by[i].length; k++) {
				tmpCardData[i * by.length + k] = by[i][k];
			}
		}
		String strCardData = sprintf_BYTE(tmpCardData, count);
		return strCardData;
	}

	public static String sprintf_BYTE(Integer by[], int count) {
		return sprintf_INT32(by, count);
	}

	public static String sprintf_BYTE(int by[], int count) {
		return sprintf_INT32(by, count);
	}

	public static String sprintf_DWORD(int dw[], int count) {
		return sprintf_INT32(dw, count);
	}

	public static String sprintf_INT32(Integer dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}
	
	public static String sprintf_INT32(int dw[], int count) {
		if (count < 1) {
			return "";
		}
		StringBuffer out_str = new StringBuffer();
		out_str.append(dw[0]);
		for (int i = 1; i < count; i++) {
			out_str.append(",");
			out_str.append(dw[i]);
		}
		return out_str.toString();
	}
	
	public static String sprintf_INT32(int[][] dw, int count) {
		if (count < 1) {
			return "";
		}
		
		StringBuffer out_str = new StringBuffer();
		
		for(int i = 0; i < dw.length; i ++)
		{
			out_str.append(dw[i][0]);
			for (int j = 1; j < dw[i].length; j++) {
				out_str.append(",");
				out_str.append(dw[i][j]);
			}
			
			out_str.append("|");
		}
		
		return out_str.toString();
	}
}

/***
 * 玩家请求进入房间
 */
class SUBCMD_S_Connect extends IJsonExport {

	int m_lUid;

	String getJsonData() {
		String bjzmsg = String.format("connect|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_Join extends IJsonExport {

	int m_lUid;

	String getJsonData() {

		String bjzmsg = String.format("join|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

// 离开房间通知
class SUBCMD_S_Leave extends IJsonExport {

	int m_lUid;// 玩家ID

	String getJsonData() {

		String bjzmsg = String.format("leave|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_InBack extends IJsonExport{
	int byActionUser;
	String getJsonData(){
		String bjzmsg = String.format("inBack|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);
		return json.toString();
	}
}
class SUBCMD_S_InFore extends IJsonExport{
	int byActionUser;
	String getJsonData(){
		String bjzmsg = String.format("inFore|%d", byActionUser);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);
		return json.toString();
	}
}
// 离开房间通知
class SUBCMD_S_Offline extends IJsonExport {

	int m_lUid;// 玩家ID

	String getJsonData() {

		String bjzmsg = String.format("offline|%d", m_lUid);

		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_CreateRoom extends IJsonExport {

	int cbResult;
	int cbRound;
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String bjzmsg = String.format("createroom|%d|%d|%d|%d", cbResult, cbRound, m_wUserChairID, m_dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_Param extends IJsonExport {

	int m_dwTableID;// 房间ID
	String szParam;

	String getJsonData() {

		String bjzmsg = String.format("param|%d|%s", m_dwTableID, szParam);

		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_TryDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String bjzmsg = String.format("try_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_AgreeDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String bjzmsg = String.format("agree_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);

		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_RefuseDismissRoom extends IJsonExport {
	int lUid;
	String szNickName;//
	int dwTableID;// 房间ID

	String getJsonData() {
		String bjzmsg = String.format("refuse_dismissroom|%d|%s|%d", lUid, szNickName, dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_DismissRoom extends IJsonExport {
	int cbResult;
	int lUid;
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String bjzmsg = String.format("dismissroom|%d|%d|%d|%d", cbResult, lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_JoinRoom extends IJsonExport {
	int lUid;
	int cbResult;
	int dwTableID;// 房间ID
	int cbRound;
	int byParam[] = new int[20];
	String szGameName;
	String szGameDesc;

	String getJsonData() {

		String strParam = Arrays.toString(byParam);
		strParam = strParam.substring(1, strParam.length() - 1);

		String bjzmsg = String.format("joinroom|%d|%d|%d|%d|%s|%s|%s", lUid, cbResult, dwTableID, cbRound, strParam,
				szGameName, szGameDesc);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_AvatarURL extends IJsonExport { 		
	int	lUid;  
	String szURL;

	String getJsonData() {

		String bjzmsg = String.format("avatar|%d|%s", lUid, szURL);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_Sit extends IJsonExport{		
	int	 m_lUid;      	
	int	 m_wUserChairID;//座位ID 
	int	 m_dwTableID;//房间ID
	int	 m_lUserScore;
	String	szNickName;
	int	m_cbGender;
	int		m_iAvatar;
	int		m_nState;
	String	szIP;

	String getJsonData() {

		String bjzmsg = String.format("sit|%d|%d|%d|%d|%s|%d|%d|%s|%d", m_lUid, m_wUserChairID, m_dwTableID,
				m_lUserScore, szNickName, m_cbGender, m_iAvatar,szIP, m_nState);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_DenySit extends IJsonExport {
	int cbReason; // 1,没有找到房间,2，房间已满

	String getJsonData() {

		String bjzmsg = String.format("denysit|%d", cbReason);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_Look extends IJsonExport{ 
	int m_lUid;     	
	int m_wUserChairID;//房间ID    	
	int m_iTotalCoin;
	String szNickName;

	String getJsonData() {

		String bjzmsg = String.format("look|%d|%d|%d|%d|%s", m_lUid, m_wUserChairID, m_iTotalCoin, szNickName);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_StandUp extends IJsonExport {

	int m_lUid;// 玩家ID
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String bjzmsg = String.format("standup|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_Kick extends IJsonExport {

	int m_lUid;// 玩家ID
	int m_wUserChairID;// 座位ID
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String bjzmsg = String.format("kick|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};


class SUBCMD_S_Error extends IJsonExport {
	int byRound;// 玩家ID
	int bySeatID;// 玩家座位
	int errCode;// 玩家座位
	String errMsg;// 房间ID

	String getJsonData() {

		String bjzmsg = String.format("error|%d|%d|%d|%s", byRound, bySeatID,errCode, errMsg);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_VoiceMsg extends IJsonExport{
	int m_lUid;
	int m_wUserChairID;
	int m_maxClip;
	int m_currClip;
	float seconds;
	String data;
	
	String getJsonData() {

		String mjmsg = String.format("voicemsg|%d|%d|%f|%s|%d|%d", m_lUid, m_wUserChairID, seconds, data,m_maxClip,m_currClip);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", mjmsg);

		return json.toString();
	}
};

class SUBCMD_S_Ready extends IJsonExport {
	int m_lUid;// 玩家ID
	int m_wUserChairID;// 玩家座位
	int m_dwTableID;// 房间ID

	String getJsonData() {

		String bjzmsg = String.format("ready|%d|%d|%d", m_lUid, m_wUserChairID, m_dwTableID);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

// 聊天表情
class SUBCMD_S_BiaoQing extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位
	int m_iBiaoQingIndex;

	String getJsonData() {

		String bjzmsg = String.format("biaoqing|%d|%d|%d", m_lUid, m_wUserChairID, m_iBiaoQingIndex);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_YuYin extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	int m_iYuYinIndex;

	String getJsonData() {

		String bjzmsg = String.format("yuyin|%d|%d|%d", m_lUid, m_wUserChairID, m_iYuYinIndex);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

// 送礼
class SUBCMD_S_SongLi extends IJsonExport {
	int m_srcUid;// 哪个玩家ID获得
	int m_dstUid;// 玩家座位 号
	int m_iLiWu;
	int m_srcCoin;// 送礼的人余下多少钱
	int m_dstCoin;// 收礼的人余下多少钱

	String getJsonData() {

		String bjzmsg = String.format("use|%d|%d|%d|%d|%d", m_srcUid, m_dstUid, m_iLiWu, m_srcCoin, m_dstCoin);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_Avatar extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	String szAvatarURL;

	String getJsonData() {

		String bjzmsg = String.format("avatar|%d|%s", m_lUid, szAvatarURL);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_Chat extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	String szContent;

	String getJsonData() {

		String bjzmsg = String.format("chat|%d|%d|%s", m_lUid, m_wUserChairID, szContent);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

// 语音
class SUBCMD_S_Voice extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	int seconds;
	String szVoiceURL;

	String getJsonData() {

		String bjzmsg = String.format("voice|%d|%d|%d|%s", m_lUid, m_wUserChairID, seconds, szVoiceURL);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SSeatInfo {
	int m_lUid;// UID
	int m_iTotalCoin;// COIN
	String m_NickName;// NICKNAME
	int m_iBetCoin;//
	int m_cbGender;//
	int m_iAvatar;//
	int m_cbUserStatus;// 用户状态
	int m_iVipLevel;// VIP LEVEL
	int m_iTitle;// 称号
	int m_isLookon;// 是否观众
	String szIP;

	public String toString() {

		String bjzmsg = String.format("%d#%d#%s#%d#%d#%d#%d#%d#%d#%d#%s", m_lUid, m_iTotalCoin, m_NickName, m_iBetCoin,
				m_cbGender, m_iAvatar, m_cbUserStatus, m_iVipLevel, m_iTitle, m_isLookon, szIP);
		return bjzmsg;
	}
};

class SUBCMD_S_Table extends IJsonExport{ //同步房间玩家信息
	int	 m_dwTableID;//房间ID			
	int	m_bTableStarted;//只要开始玩
	int	m_byRound;//
	int	m_byMaxRound;//		
	int	m_bGameStarted;//游戏开始	
	int	m_cntUser;//玩家数量
	int	m_cntLookon;//观众数量
	String vecInputWenZi;
	public SUBCMD_S_Table(){
		for (int i = 0; i < 5; i++) {
			 m_seatInfo[i] = new SSeatInfo();
		}
	}
	SSeatInfo	m_seatInfo[] = new SSeatInfo[5];
	public String getJsonData(){
		String bjzmsg = String.format("table|%d|%d|%d|%d|%d|%d|%d|%s|%s|%s|%s|%s|%s", m_dwTableID, m_bTableStarted, m_byRound, m_byMaxRound,m_bGameStarted, m_cntUser, m_cntLookon,
			m_seatInfo[0].toString(), m_seatInfo[1].toString(), m_seatInfo[2].toString(), 
			m_seatInfo[3].toString(),m_seatInfo[4].toString(),vecInputWenZi);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);	
		
		return json.toString();		
	}
};
//语音
class SUBCMD_S_Text extends IJsonExport {
	int m_lUid;// 哪个玩家ID获得
	int m_wUserChairID;// 玩家座位号
	String szContent;
	String InputWenZi;
	String getJsonData() {
		String mjmsg = String.format("text|%d|%d|%s|%s", m_lUid, m_wUserChairID, szContent,InputWenZi);

		JSONObject json = new JSONObject();
		json.put("command", "mjmsg");
		json.put("mjmsg", mjmsg);
		return json.toString();
	}
};

//用户出牌
class SUBCMD_S_TableBegin extends IJsonExport {
	String strParam;
	int byRound;//
	int byMaxRound;
	int nPeiPaiCountDown;// 配牌倒计时
	int	byPeiPai[] = new int[9];//配牌牌值
	int	bIsReady[] = new int[5];//
	int	bIsKaiPaiReady[] = new int[5];//
	int	bIsGiveUP[] = new int[5];//弃牌状态
	int lScore[] = new int[5];


	String getJsonData() {
		
		String strScore = sprintf_INT32(lScore, 5);
		String strIsReady = sprintf_INT32(bIsReady, 5);
		String strIsKaiPaiReady = sprintf_INT32(bIsKaiPaiReady, 5);
		String strIsGiveUp = sprintf_INT32(bIsGiveUP, 5);
		String strPai = sprintf_BYTE(byPeiPai, 9);

		String bjzmsg = String.format("table_begin|%s|%d|%d|%s|%s|%s|%s|%s|%s", strParam, byRound,byMaxRound,strIsReady,strIsKaiPaiReady,strScore,strIsGiveUp,nPeiPaiCountDown,strPai);
		
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);
		
		return json.toString();
	}
};

//用户出牌
class SUBCMD_S_TableSide extends IJsonExport {
	int bySeatID;
	int	bIsReady;//
	int	bIsKaiPaiReady;//
	int vecCardType[] = new int[3];
	int byPai[] = new int[9]; // 桌面扑克 //been 4
	String getJsonData() {

		String strCardType = sprintf_BYTE(vecCardType, 3);
		String strPai = sprintf_BYTE(byPai, 9);
		
		String bjzmsg = String.format("table_side|%d|%d|%d|%s|%s", bySeatID,bIsReady,bIsKaiPaiReady,strCardType, strPai);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

//用户出牌
class SUBCMD_S_TableEnd extends IJsonExport {
	int cbSceneStatus;

	String getJsonData() {

		String bjzmsg = String.format("table_end|%d", cbSceneStatus);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_STAGE extends IJsonExport { // 同步房间玩家信息
	String szStage;
	int needDealTime;	
	int	vecIsReady[] = new int[5];//
	int	vecIsKaiPaiReady[] = new int[5];//
	int m_vecCardType[][] = new int[5][3];
	int m_bTableCardArray[][] = new int[5][9]; // 桌面扑克 //been 4
	

	public String getJsonData(){

		String strReady = sprintf_BYTE(vecIsReady, 5);
		String strKaiPaiReady = sprintf_BYTE(vecIsKaiPaiReady, 5);
		String strCardType = "";//sprintf_BYTE(m_vecCardType, 5);		
		String strTableCard = "";//sprintf_BYTE(m_bTableCardArray, 52);		
		
		String bjzmsg = String.format("stage|%s|%d|%s|%s|%s|%s", szStage, needDealTime, strReady,strKaiPaiReady, strCardType,strTableCard);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);		

		return json.toString();
	}
};

class SUBCMD_S_REPORT extends IJsonExport {
	int cbReason;
	int whoDismiss;
	int vecMaxWinScore[] = new int[5];
	int vecWinScore[] = new int[5];
	int vecLoseScore[] = new int[5];
	int vecResultScore[] = new int[5];
	int [][] vecDetailGroupScore = new int[5][5]; //每一道牌赢的次数和喜分次数

	String getJsonData() {

		String strMaxWinScore = sprintf_INT32(vecMaxWinScore, 5);
		String strWinScore = sprintf_INT32(vecWinScore, 5);
		String strLoseScore = sprintf_INT32(vecLoseScore, 5);
		String strResultScore = sprintf_INT32(vecResultScore, 5);
		String strDetailGroupScore = sprintf_INT32(vecDetailGroupScore, 5);
		String bjzmsg = String.format("report|%d|%d|%s|%s|%s|%s|%s", cbReason, whoDismiss, strMaxWinScore, strWinScore,
				strLoseScore, strResultScore,strDetailGroupScore);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}

	String getData() {

		String strWinScore = sprintf_INT32(vecWinScore, 5);
		String strLoseScore = sprintf_INT32(vecLoseScore, 5);
		String strResultScore = sprintf_INT32(vecResultScore, 5);

		return String.format("report|%d|%d|%s|%s|%s", cbReason, whoDismiss, strWinScore, strLoseScore, strResultScore);
	}
};


/***
 * 房间信息
 */
class SUBCMD_S_CardStatus extends IJsonExport {// 同步房间玩家信息
	int m_cbCardStatus[] = new int[5];

	String getJsonData() {
		String card_status = Arrays.toString(m_cbCardStatus);
		card_status = card_status.substring(1, card_status.length() - 1);

		String bjzmsg = String.format("card_status|%s", card_status);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};


/***
 * 房间信息
 */
class SUBCMD_S_StatusFree extends IJsonExport {// 同步房间玩家信息

	int m_lCellScore;// 房间ID

	String getJsonData() {

		String bjzmsg = String.format("status_free|%d", m_lCellScore);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};


//同步房间玩家信息
class SUBCMD_S_StatusPlay extends IJsonExport {
	int m_lCellScore;// 房间ID
	int m_cntTableChip[] = new int[5];// 1x,3x,5x,8x,10x
	int m_cbCardStatus[] = new int[5];
	int m_AllBetCoin[] = new int[5];// 底注
	int m_AllUserCoin[] = new int[5];// 每个玩家多少钱

	String getJsonData() {
		String strTableChip = Arrays.toString(m_cntTableChip);
		strTableChip = strTableChip.substring(1, strTableChip.length() - 1);

		String strCardStatus = Arrays.toString(m_cbCardStatus);
		strCardStatus = strCardStatus.substring(1, strCardStatus.length() - 1);

		String strBetCoin = Arrays.toString(m_AllBetCoin);
		strBetCoin = strBetCoin.substring(1, strBetCoin.length() - 1);

		String strUserCoin = Arrays.toString(m_AllUserCoin);
		strUserCoin = strUserCoin.substring(1, strUserCoin.length() - 1);

		String bjzmsg = String.format("status_play|%d|%s|%s|%s|%s", m_lCellScore, strTableChip, strCardStatus,
				strBetCoin, strUserCoin);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_Start extends IJsonExport 
{
	int		byRound;//
	int		byMaxRound;//	
	int		vecIsReady[] = new int[5];//
	public String getJsonData(){
		String strIsReady = sprintf_BYTE(vecIsReady, 5);

		String bjzmsg = String.format("start|%d|%d|%s", byRound, byMaxRound,strIsReady);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();			
	}
};

class SUBCMD_S_FaPai extends IJsonExport 
{
	int		byRound;//
	int		byMaxRound;//	
	int		vecIsReady[] = new int[5];//
	int		m_nPeiPaiCountDown;//配牌倒计时
	int		byPai[] = new int[9];			// 
	public String getJsonData(){
		String strIsReady = sprintf_BYTE(vecIsReady, 5);
		String strPai = sprintf_BYTE(byPai, 9);

		String bjzmsg = String.format("fapai|%d|%d|%s|%s|%s", byRound, byMaxRound,strIsReady, strPai,m_nPeiPaiCountDown);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();			
	}
};

// 每局战绩详情
class SUBCMD_S_ROUND_RECORD extends IJsonExport 
{
	// 战绩记录
	public int m_vecRecordRoundPai[][] = new int[5][9]; // 每一局牌值
	public int m_vecRecordRoundScore[] = new int[5];// 每一局的总分数
	public int m_vecRecordRoundScoreDetail[][] = new int[5][3]; // 每一局每道牌的得分
	public String m_vecRecordRoundXifen[] = new String[5]; // 每一局每道牌的喜分 
	public int m_vecPlayerChairId[] = new int [5]; //玩家列表
	public int m_nRound = 0; // 当前局数
	
	public String getJsonData(){
		String strRoundScore = sprintf_BYTE(m_vecRecordRoundScore, 5);
		String strRoundPai = sprintf_BYTE(m_vecRecordRoundPai, 45);
		String strRoundScoreDetail = sprintf_BYTE(m_vecRecordRoundScoreDetail, 15);
		String strPlayerChairId = sprintf_BYTE(m_vecPlayerChairId, 5);

		String strXiFen = "";
		for(int i = 0; i < 5 ; i ++)
		{
			if(i < 4)
			{
				strXiFen += m_vecRecordRoundXifen[i] + "#";
			}else{
				strXiFen += m_vecRecordRoundXifen[i];
			}
		}
		
		String bjzmsg = String.format("roundRecord|%s|%s|%s|%s|%s|%d", strRoundScore, strRoundPai,strRoundScoreDetail, strXiFen,strPlayerChairId,m_nRound);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();			
	}
};

class SUBCMD_S_QiangZhuang extends IJsonExport {
	int lUid; // 当前玩家
	int wChairID; // 玩家座位号
	int wPower; // 下注金币

	public String getJsonData() {

		String bjzmsg = String.format("qiangzhuang|%d|%d|%d", lUid, wChairID, wPower);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_DingZhuang extends IJsonExport {
	int lUid; // 当前玩家
	int wChairID; // 玩家座位号
	int wPower; // 下注金币
	int byQiangZhuang[] = new int[5]; // 抢庄玩家的动画需要

	public String getJsonData() {

		String strQiangZhuang = sprintf_BYTE(byQiangZhuang, 5);

		String bjzmsg = String.format("dingzhuang|%d|%d|%d|%s", lUid, wChairID, wPower, strQiangZhuang);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();

	}
};
class SUBCMD_S_KaiPaiReady extends IJsonExport 
{
	int		byRound;//	
	int		vecIsKaiPaiReady[] = new int[5];// 
	int		byPai[] = new int[9];
	int		wChairID = 0;
	public String getJsonData(){
		String strIsKaiPaiReady = sprintf_BYTE(vecIsKaiPaiReady, 5);
		String strPai = sprintf_BYTE(byPai, 9);
		String bjzmsg = String.format("kaipai_ready|%d|%s|%s|%s", byRound,strIsKaiPaiReady,strPai,wChairID);
		
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();			
	}
};
//发送弃牌消息
class SUBCMD_S_GiveUp extends IJsonExport 
{
	int	byRound;//	
//	int	vecIsKaiPaiReady[] = new int[5];// 
	int m_vecIsGiveUp[] = new int[5]; 
	public String getJsonData(){
//		String strIsKaiPaiReady = sprintf_BYTE(vecIsKaiPaiReady, 5);
		String strGiveUp = sprintf_BYTE(m_vecIsGiveUp, 5);
		String bjzmsg = String.format("pai_giveup|%d|%s",byRound,strGiveUp);
		
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();			
	}
};

class SUBCMD_S_JieSuan extends IJsonExport {
	int		byRound;//
	int 	nRoundScore[] = new int[5];
	int 	nUserScore[] = new int[5];
	
	int		vecIsReady[] = new int[5];//	
	int		byPai[][] = new int[5][9];			// 	
	public String getJsonData(){
		
		String strRoundScore = sprintf_INT32(nRoundScore, 5);
		String strResultScore = sprintf_INT32(nUserScore, 5);
		
		String strIsReady = sprintf_BYTE(vecIsReady, 5);
		
		String strPai0 = sprintf_BYTE(byPai[0], 9);
		String strPai1 = sprintf_BYTE(byPai[1], 9);
		String strPai2 = sprintf_BYTE(byPai[2], 9);
		String strPai3 = sprintf_BYTE(byPai[3], 9);
		String strPai4 = sprintf_BYTE(byPai[4], 9);
		


		String bjzmsg = String.format("jiesuan|%d|%s|%s|%s|%s|%s|%s|%s|%s", byRound, strRoundScore, strResultScore,strIsReady, strPai0, strPai1, strPai2, strPai3,strPai4);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};

class SUBCMD_S_SuanFen extends IJsonExport {
	int		byRound;//
	int		nScore[][] = new int[5][4];
	String  xifenTypeList[] = new String[5];
	public String getJsonData(){
		
		String strScore00 = sprintf_BYTE(nScore[0], 4);
		String strScore10 = sprintf_BYTE(nScore[1], 4);
		String strScore20 = sprintf_BYTE(nScore[2], 4);
		String strScore30 = sprintf_BYTE(nScore[3], 4);
		String strScore40 = sprintf_BYTE(nScore[4], 4);
		
		String strXifen = "";
		for(int i = 0; i < xifenTypeList.length; i ++)
		{
			strXifen += xifenTypeList[i] + "#";
		}
		
		String bjzmsg = String.format("suanfen|%d|%s|%s|%s|%s|%s|%s",byRound,
				strScore00,	strScore10, strScore20,	strScore30,	strScore40,strXifen);
		JSONObject json = new JSONObject();
		json.put("command", "bjzmsg");
		json.put("bjzmsg", bjzmsg);

		return json.toString();
	}
};